$(function () {
    initHistogram();
    initPieChart();
});

/**
 * 初始化柱状图
 */
function initHistogram() {
    // app.title = '坐标轴刻度与标签对齐';
    var option = {
        color: ['#3398DB'],
        tooltip: {
            trigger: 'axis',
            axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
            }
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis: [
            {
                type: 'category',
                data: ['价格', '安全', '优惠', '配置', '外形', '舒适', '油耗', '活动', '内饰', '保养'],
                axisTick: {
                    alignWithLabel: true
                }
            }
        ],
        yAxis: [
            {
                type: 'value'
            }
        ],
        series: [
            {
                name: '次数',
                type: 'bar',
                barWidth: '60%',
                data: [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
            }
        ]
    };
    var histogram = echarts.init(document.getElementById("histogram"));
    histogram.setOption(option);
}

/**
 * 初始化饼图
 */
function initPieChart() {
    var option = {
        title: {
            text: '问“价格”问题的客户还对这些方面感兴趣',
            x: 'center',
            top: 50
        },
        tooltip: {
            trigger: 'item',
            formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        // legend: {
        //     orient: 'vertical',
        //     left: 'left',
        //     data: ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎']
        // },
        series: [
            {
                name: '客户还对这些方面感兴趣',
                type: 'pie',
                radius: '60%',
                center: ['50%', '60%'],
                data: [
                    {value: 10, name: '价格'},
                    {value: 9, name: '安全'},
                    {value: 8, name: '优惠'},
                    {value: 7, name: '配置'},
                    {value: 6, name: '外形'},
                    {value: 5, name: '舒适'},
                    {value: 4, name: '油耗'},
                    {value: 3, name: '活动'},
                    {value: 2, name: '内饰'},
                    {value: 1, name: '保养'}
                ],
                itemStyle: {
                    emphasis: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }
        ]
    };
    var pieChart = echarts.init(document.getElementById("pieChart"));
    pieChart.setOption(option);
}